package com.app.onebuy.user;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.app.onebuy.R;
import com.app.onebuy.basis.BasisActivity;
import com.app.onebuy.basis.Constants;
import com.app.onebuy.bean.InviteHasPresentBean;
import com.app.onebuy.news.NewsH5DetailActivity;
import com.app.onebuy.util.JiGuangUtil;

import butterknife.BindView;
import butterknife.OnClick;
import cn.jiguang.share.android.api.Platform;
import cn.jiguang.share.android.api.ShareParams;
import my.http.MyHttpListener;
import my.http.MyHttpUtils;
import my.http.MyParams;

/**
 * Created by otis on 2018/6/7.
 */

public class InviteHasPresentActivity extends BasisActivity{

    @BindView(R.id.text_shareget)
    TextView mTvShareGet;
    @BindView(R.id.text_people)
    TextView mTvPeople;
    @BindView(R.id.text_intergral)
    TextView mTvIntergral;

    InviteHasPresentBean inviteHasPresentBean;

    @Override
    public void initViews() {
        super.initViews();
        setContentView(R.layout.user_invite_now_activity);

        setTitle(mContext.getString(R.string.invite_invite_has_present));
        setTitleLeftButton(R.drawable.base_icon_back_white, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        setTitleRightText(R.string.invite_rule, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NewsH5DetailActivity.toDetail(mContext,"recommended_rule",true);
            }
        });
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        super.initData(savedInstanceState);
        getList();
    }

    private void getList(){
        MyParams params = new MyParams();
        MyHttpUtils.get(Constants.URL_RECOMMEND_INDEX, params, new MyHttpListener() {
                    @Override
                    public void onSuccess(int httpWhat, Object result) {
                        if(isFinishing())return;
                        inviteHasPresentBean = (InviteHasPresentBean) result;
                        setView(inviteHasPresentBean);
                    }

                    @Override
                    public void onFinish(int httpWhat) {
                        if(isFinishing())return;
                    }
                },
                0, InviteHasPresentBean.class);
    }

    private void setView(InviteHasPresentBean bean){
        mTvShareGet.setText(""+bean.getReward_price()+mContext.getString(R.string.unit_money));
        mTvPeople.setText(""+bean.getSuccess_num());
        mTvIntergral.setText(""+bean.getReward_price()+mContext.getString(R.string.unit_money));
    }

    @OnClick(R.id.view_list)
    void rewardlist(){
        if(inviteHasPresentBean == null){
            getList();
            return;
        }
        Intent intent = new Intent(mContext,InviteRewardListActivity.class);
        intent.putExtra("data",inviteHasPresentBean);
        startActivity(intent);
//        ActivityTool.skipActivity(mContext,InviteRewardListActivity.class);
    }
    @OnClick(R.id.btn_ok)
    void share(){
        if(inviteHasPresentBean == null){
            getList();
            return;
        }
        ShareParams shareParams = new ShareParams();
        shareParams.setShareType(Platform.SHARE_WEBPAGE);
        shareParams.setImageUrl(inviteHasPresentBean.getShare_imgage_id());
        shareParams.setUrl(inviteHasPresentBean.getRecommended_url());
        JiGuangUtil.showBroadView(InviteHasPresentActivity.this,shareParams);
//        new DialogShare(mContext,inviteHasPresentBean).show();
    }

}
